import cv2 as cv
import numpy as np

img = cv.imread('../resources/miku.jpg')
cv.namedWindow('image', cv.WINDOW_AUTOSIZE)
cv.createTrackbar('Brightness', 'image', 0, 255, lambda x: None) # trackbar name, window name, min, max, callback function

blank = np.zeros(img.shape, dtype=np.uint8)

while True:
    pos = cv.getTrackbarPos('Brightness', 'image') - 128
    if pos >= 0:
        blank[:,:] = (pos, pos, pos)
        # img_brightness = cv.convertScaleAbs(img, alpha=1, beta=brightness)
        cv.imshow('image', cv.add(img, blank))
    else:
        blank[:,:] = (-pos, -pos, -pos)
        cv.imshow('image', cv.subtract(img, blank))

    if cv.waitKey(1) == ord('q'):
        break